#include "status_control/status_control.hpp"

#ifdef DBG_TAG
#undef DBG_TAG
#endif
#ifdef DBG_LVL
#undef DBG_LVL
#endif

#define DBG_TAG "status_ctl"
#define DBG_LVL DBG_LOG

extern "C"
{
#include <rtdbg.h>
}
/******************************************************************************
 *
 * @brief:    补光板
 *
 ******************************************************************************/
void led_board_thread_entry(void *pra)
{

    led_board_pwm->CHIP_PWM_close();
    fan_pwm->CHIP_PWM_close();

    led_board_pwm->CHIP_PWM_open_debug();
    led_board_pwm->CHIP_PWM_open();
    fan_pwm->CHIP_PWM_open_debug();
    fan_pwm->CHIP_PWM_open();
    while(1)
    {
//        LOG_D("set to 0");
        led_board_pwm->CHIP_PWM_change_duty_ratio(0);
        fan_pwm->CHIP_PWM_change_duty_ratio(0);
        rt_thread_mdelay(1000);
//        LOG_D("set to 50");
        led_board_pwm->CHIP_PWM_change_duty_ratio(50);
        fan_pwm->CHIP_PWM_change_duty_ratio(50);
        rt_thread_mdelay(1000);
//        LOG_D("set to 80");
        led_board_pwm->CHIP_PWM_change_duty_ratio(80);
        fan_pwm->CHIP_PWM_change_duty_ratio(80);
        rt_thread_mdelay(1000);
//        LOG_D("set to 100");
        led_board_pwm->CHIP_PWM_change_duty_ratio(100);
        fan_pwm->CHIP_PWM_change_duty_ratio(100);
        rt_thread_mdelay(1000);

    }
}
/******************************************************************************
 *
 * @brief:     轮速传感器
 *
 ******************************************************************************/



void sim_sig_thread_entry(void *pra)
{
    sim_sig->SIMULATE_SIGNAL_in_thread_function();
}

int sim_sig_add()
{
//    for(int i = 0; i < 10; i++)
        while(1)
        {
            sim_sig->SIMULATE_SIGNAL_add_a_signal();
            sim_sig->SIMULATE_SIGNAL_add_a_signal();
            sim_sig->SIMULATE_SIGNAL_add_a_signal();
            sim_sig->SIMULATE_SIGNAL_add_a_signal();
            rt_thread_mdelay(1);
        }

    return 0;
}
MSH_CMD_EXPORT(sim_sig_add,sim_sig_add)


/******************************************************************************
 *
 * @brief:    开启所有有状态控制
 *
 ******************************************************************************/

void status_control_thread_start()
{
    rt_thread_t tid;

    tid = rt_thread_create("led_b", led_board_thread_entry, RT_NULL, 2048, 16, 20);
    if (tid)
        rt_thread_startup(tid);
    else
        LOG_E("led_b thread not start!");


    tid = rt_thread_create("sim_sig", sim_sig_thread_entry, RT_NULL, 2048, 10, 20);
    if (tid)
        rt_thread_startup(tid);
    else
        LOG_E("sim_sig thread not start!");

}

